# 到日解析json的包，官方包
import json

json_str = '{"age":22,"clazz":"理科六班","gender":"女","id":"1500100008","name":"符半双"}'

# 解析json字符串
# 将json字符串转换成字典
json_obj = json.loads(json_str)
print(json_obj)
print(json_obj["id"])
print(json_obj["name"])
age = json_obj["age"]  # 不能自动在代码中推断类型，运行的时候知道类型
print(age, type(age))

with open("students.json", "r", encoding="utf-8") as f:
    # 读取所有的数据
    lines = f.readlines()
    # 批量解析json
    students = [json.loads(line) for line in lines]

for student in students:
    print(student, type(student))
